<?php

session_start();
error_reporting(0);

if(!isset($_SESSION['user_id'])){
	require_once("../config.php");
	header("location:$home_url");
	exit;
}
$module = $_GET['m'];

if($module == 'product_detail'){
	require_once("simple_html_dom.php");
	$link_product = $_GET['link'];
	$html = file_get_html($link_product);
	if($html){
		$title = $html->find("h1",0)->plaintext;
		
		$arr = parse_url($link_product);
		$path = explode("/",$arr['path']);
		
		if(preg_match("/\.html$/",$path[1])){
			$category = "Băng Tước";
		}else{
			$category = str_replace("-"," ",$path[1]);
		}
		
		$img = $html->find("div.LGImgWrap a.highslide img",0)->src;
		$price = $html->find("select#size option",0)->plaintext;
		$price = preg_replace("/\([a-zA-Z]+\)\s/","",$price);
		$price = str_replace(array('$','.00'),'',$price);
		$data=array(
			'name'		=> $title,
			'category'	=> $category,
			'price'		=> $price,
			'photo'		=> $img
		);
		echo json_encode($data);
	}
}else{
	
}